﻿Imports Mystery

Public Class StringContainFilter
    Implements IPropertyFilterControl

    Private _content_property As ContentProperty

    Public Property content_property As System.Reflection.PropertyInfo Implements IPropertyFilterControl.content_property
        Get
            Return _content_property.used_in
        End Get
        Set(value As System.Reflection.PropertyInfo)
            _content_property = value.getMysteryAttribute(Of ContentProperty)()
        End Set
    End Property

    Public Event haveChanged() Implements IPropertyFilterControl.haveChanged

    Public Property label As String Implements IPropertyFilterControl.label
        

    Public Function Match(content As Mystery.IContent) As Boolean Implements IPropertyFilterControl.Match
        If String.IsNullOrEmpty(tbValue.Text) Then Return True
        Dim value As String = tbValue.Text
        Dim content_value As Object = _content_property.retrive(content)
        If TypeOf (content_value) Is ContentPropertyValue Then content_value = DirectCast(content_value, ContentPropertyValue).getValue
        Dim str As String = CStr(content_value)
        If String.IsNullOrEmpty(str) Then Return False
        Return str.ToLower.Contains(value.ToLower)
    End Function

    Private Sub tbValue_LostFocus(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles tbValue.LostFocus
        RaiseEvent haveChanged()
    End Sub

   
    Private Sub tbValue_KeyDown(sender As System.Object, e As System.Windows.Input.KeyEventArgs) Handles tbValue.KeyDown
        If e.Key = Key.Enter Then
            RaiseEvent haveChanged()
        End If
    End Sub
End Class
